<template>
    <div>
        <div class="cbody">
        <div class="top">
          <div :class="dayChange == 0 ? 'hac' : ''" @click="setDays(0)">全部</div>
          <div :class="dayChange == 1 ? 'hac' : ''" @click="setDays(1)">今日</div>
          <div :class="dayChange == 2 ? 'hac' : ''" @click="setDays(2)">近7天</div>
          <div :class="dayChange == 3 ? 'hac' : ''" @click="setDays(3)">近30天</div>
        </div>
        <div class="info">
          <div class="head">
            <div>
              <div class="name">合伙人收入</div>
              <div class="count">￥{{money.pt.toFixed(2)}}</div>
            </div>
            <div>
              <div class="name">合伙人数量</div>
              <div class="count">{{money.hh}}</div>
            </div>
            <div>
              <div class="name">账户余额</div>
              <div class="count">￥{{money.fw.toFixed(2)}}</div>
            </div>
            <div>
              <div class="name">已提现金额</div>
              <div class="count">￥{{money.yj.toFixed(2)}}</div>
            </div>
          </div>
          <div class="screen">
            合伙人列表
          </div>
          <div v-loading="loading">
           <!--  <div class="sel">
              <span>名称：</span>
              <input type="text" placeholder="服务商名称/合伙人" v-model="params.keyWord">
              <span>当前状态：</span>
              <select name  v-model="params.ord">
                <option value="">请选择</option>
                <option :value="0">待审核 </option>
                <option :value="1">审核通过未打款 </option>
                <option :value="2">审核通过已打款 </option>
                <option :value="3">审核失败</option>
              </select>
              <el-button
                type="primary"
                @click="search"
                >
                查询
              </el-button>
            </div> -->
            <div class="parchange">
              <div :class="params.ord== 1 ? 'aced' : ''" @click="setType(1)">默认</div>
              <div :class="params.ord== 2 ? 'aced' : ''" @click="setType(2)">收入</div>
              <div :class="params.ord== 3 ? 'aced' : ''" @click="setType(3)">提现</div>
              <div :class="params.ord== 4 ? 'aced' : ''" @click="setType(4)">余额</div>
            </div>
            <div class="table">
              <div class="thead">
                <div class="username">合伙人名称</div>
                <div class="parsr">合伙人收入</div>
                <div class=" txmoney">已提现金额</div>
                <div class="accmoney">账户余额</div>
                <div class="ptmoney">平台佣金</div>
                <div class="ctrl">操作</div>
              </div>
              <div class="tbody" v-for="(item,index) in list" :key="index">
                <div class="username firstchild">
                  <span :title="item.partner_name">{{ item.partner_name }}</span>
                </div>
                <div class="parsr">
                  <span>￥ {{ item.shou.toFixed(2)}}</span>
                </div>
                <div class="txmoney">￥{{ item.ti.toFixed(2) }}</div>
                <div class=" accmoney">￥{{ item.balance.toFixed(2) }}</div>
                <div class="ptmoney">￥{{item.commission.toFixed(2)}}</div>
                <div  class="ctrl" style="color:#085dab" @click="details(item.id)">收入明细</div>
                <div v-if="roleList.search('财务管理') != '-1'" class="ctrl" style="color:#085dab" @click="details(item.id)">收入明细</div>
              </div>
              <div style="padding: 50px 0;text-align: center;">
                <el-pagination
                  class="el-pagination"
                  background
                  layout="prev, pager, next"
                  :page-count="pageTotal"
                  @current-change="changePage"
                  >
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="popup_details" ref="popup_details">
        <el-table
          :data="detailsList"
          border
          style="width: 100%"
          >
          <el-table-column
            prop="title"
            label="活动名称"
            >
          </el-table-column>
          <el-table-column
            prop="price"
            label="报名费用（元）"
            >
            <template slot-scope="scope">
              {{ scope.row.price.toFixed(2)}}
            </template>
          </el-table-column>
         
          <el-table-column
            prop="bi"
            label="门店分成比例"
            >
            <template slot-scope="scope">
              {{ scope.row.bi}}%
            </template>
          </el-table-column>
          <el-table-column
            prop="ping"
            label="平台佣金（元）"
            >
            <template slot-scope="scope">
              {{ scope.row.ping.toFixed(2)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="mendian"
            label="门店分成金额（元）"
            >
            <template slot-scope="scope">
              {{ scope.row.mendian.toFixed(2)}}
            </template>
          </el-table-column>
          <el-table-column
            prop="time"
            label="结算时间"
            >
            <template slot-scope="scope">
              {{ new Date ( scope.row.time ).toLocaleDateString () }}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          class="el-pagination"
          background
          layout="prev, pager, next"
          :page-count="detailsTotal"
          @current-change="detailsChangePage"
          >
        </el-pagination>
      </div>
    </div>
</template>

<style type="text/scss" lang="scss" scoped>
  .popup_details {
    display: none;
    text-align: center;
    width: 100%;
    height: 100%;
    overflow-y: scroll;
    .el-pagination {
      margin: 50px 0;
    }
  }
</style>

<script>
import Global from '../tool/Global.vue'
import axios from 'axios'
import qs from 'qs' // 将请求转换成form 表单提交形式
export default {
    created () {
      this.getFinList();
      this.getTotal();
      this.getRole()
    },
    data() {
    return {
        loading: false,
        list: [],
        params: {
            ord:1,
            limit:10,
            page:1
        },
        money: {
            pt:0,
            hh:0,
            fw:0,
            yj:0
        },
        info:{

        },
        dayChange:0,
        types: '',
        detailsList: [],
        detailsTotal: 1,
        detailsId: '',
        pageTotal: 1,
        detailsPage: {
          page: 1
        },
        roleList:''
    };
  },
  methods: {
    /**
     *  获取权限
     */
    getRole: function () {
      
      let that = this;
      axios({
          method: 'post',
          url:`${that.$store.state.url}/sysPermission/selectByEmployeeId`,
            data:qs.stringify({
              empId:that.$cookie.get('pid')
            })
      }).then(res => {
            console.log(res)
            let arr = res.data.data
            let role = []
            for(let i = 0; i < arr.length; i++) {
              role.push(arr[i].name) 
            }
            this.roleList = role.toString()
        });
    },
    changePage( argv ) {
      this.params.page = argv;
      this.getFinList();
    },
    detailsChangePage( argv ) {
      this.detailsPage.page = argv;
      this.getDetails();
    },
    // 获取弹窗信息
    getDetails( id ) {
      axios.post (
        `${this.$store.state.url}/tWithdrawal/selectDateilByPartner`,
        // qs.stringify ({
        //   id: 2
        // })
        qs.stringify ({
          partnerId: this.detailsId,
          page: this.detailsPage.page,
          limit: 10
        })
      ).then ( response => {
        let res = response.data
        if ( res.code == 0 ) {
          this.detailsList = res.data;
        }
      });
    },

    // 显示详情弹窗
    details( id ) {
      let _this = this;
      this.detailsId = id;
      this.getDetails();

      layer.open({
        type: 1,
        zIndex: 1,
        title: false,
        closeBtn: false,
        shadeClose: true,
        area: [ '800px', '550px' ],
        content: $ ( _this.$refs.popup_details ),
        btn: false,
        end () {
          _this.$refs.popup_details.style.display = 'none';
        }
      });
    },

     getTotal() {

        axios.post (
          `${this.$store.state.url}/tWithdrawal/selectMoneyByPartner`,
          qs.stringify ({
            type: 2
          })
        ).then ( response => {
          let res = response.data
          if ( res.code == 0 ) {
            this.info = res.data;
            this.setDays( 0 );
          }
        });
      },
    /**
     * 设置状态
     */
     setType:function (num) {
       this.params.ord = num;
       this.getFinList();
     },
      /**
       *  设置天数
       */
      setDays: function (num) {
          let that = this
          that.dayChange = num
          switch (num) {
              case 0:
                that.money = {
                    pt:that.info.totalPrice,
                    hh:that.info.partnerNum,
                    fw:that.info.partnerTotalPrice,
                    yj:that.info.backstageTotalPrice
                }
                break;
                case 1:
                that.money = {
                    pt:that.info.totalTodayPrice,
                    hh:that.info.partnerTodayNum,
                    fw:that.info.partnerTodayTotalPrice,
                    yj:that.info.backstageTodayTotalPrice
                }
                break;
                case 2:
                that.money = {
                    pt:that.info.totalWeekPrice,
                    hh:that.info.partnerWeekNum,
                    fw:that.info.partnerWeekTotalPrice,
                    yj:that.info.backstageWeekTotalPrice
                }
                break;
                case 3:
                that.money = {
                    pt:that.info.totalMonPrice,
                    hh:that.info.partnerMonNum,
                    fw:that.info.partnerMonTotalPrice,
                    yj:that.info.backstageMonTotalPrice
                }
                break;
          }
          console.log(that.money)
      },
      search() {
        this.getFinList();
      },
      /**
       *  查询财务列表
       */
      getFinList: function (num) {
        // let that = this;
        this.loading = true;
        let _this = this;
        axios.post (
          // `${this.$store.state.url}/tWithdrawal/selectDrawal`,
          `${this.$store.state.url}/tWithdrawal/selectByWithList`,
          qs.stringify(this.params)
        ).then ( response => {
          let res = response.data;
          if ( res.code == 0 ) {
            _this.pageTotal = Math.ceil ( res.count / 10 );
            _this.list = res.data;
          }
          this.loading = false;
        }, () => {
          this.loading = false;
        });
      },
    /*
     * 根据时间毫秒数 返回年月日
     */
    setDate: function(str) {
      let times = new Date(str);
      return `${times.getFullYear()}-${
        times.getMonth() < 10 ? "0" + times.getMonth() : times.getMonth()
      }-${times.getDate() < 10 ? "0" + times.getDate() : times.getDate()}`;
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function(str) {
      let times = new Date(str);
      return `${
        times.getHours() < 10 ? "0" + times.getHours() : times.getHours()
      }:${
        times.getMinutes() < 10 ? "0" + times.getMinutes() : times.getMinutes()
      }:${
        times.getSeconds() < 10 ? "0" + times.getSeconds() : times.getSeconds()
      }`;
    }
  },
  mounted () {

  }
}
</script>
<style scoped>
.screen,.parchange {
  /* width: 1520px; */
  height: 60px;
  background: #f6f6f6;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  margin-top: 30px;
  margin-bottom: 26px;
  font-size:18px;
color:#000000;
font-weight: bold;
padding-left: 24px;
box-sizing: border-box;
}
.parchange {
    padding: 0;
}
.parchange > div {
    display: inline-block;
    width: 110px;
    height: 36px;
    text-align: center;
    border-right: 1px solid #ddd;
    line-height: 36px;
    margin-top: 12px;
    cursor: pointer;
}
.parchange > div:last-of-type {
    height: 60px;
    margin-top: 0;
    line-height: 60px;
}
.parchange .aced {
    color:#085dab;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  height: 40px;
  line-height: 40px;
  width: 1520px;
}
.sel > span {
  font-weight: bold;
  font-size: 18px;
  color: #000000;
  float: left;
}
.sel > span:last-of-type {
  margin-left: 106px;
}
.sel > input {
  background: #ffffff;
  border: 1px solid #979797;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 38px;
  font-size: 18px;
  color: #888888;
  text-align: center;
  float: left;
  outline: none;
}
.sel > select {
  background: #ffffff;
  border: 1px solid #979797;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 38px;
  font-size: 18px;
  color: #888888;
  text-align: center;
  float: left;
  outline: none;
  padding-left: 70px;
}
.sel-btn {
  background: #085dab;
  border: 1px solid #085dab;
  width: 140px;
  height: 38px;
  font-size: 18px;
  color: #ffffff;
  text-align: center;
  float: left;
  margin-left: 50px;
  cursor: pointer;
}

.cbody {
  /* float: left; */
  padding-top:25px;
}
.info {
  /* width: 1504px; */

  height: 140px;
  background: #f6f6f6;
  margin-left: 4px;
}
.top {
  /* margin-top: 7px; */
  height: 40px;
  text-align: center;
  width: 440px;
  color: #1875f0;
  border: 2px solid #1875f0;
  box-sizing: border-box;
  border-radius: 4px;
  display: flex;
  margin:  0 auto 25px;
  /* margin-bottom: 38px;
  margin-left: 476px; */
}
.top > div {
  flex: 1;
  /* height: 40px; */
  line-height: 40px;
  font-size: 14px;
  border-left: 2px solid #1875f0;
  box-sizing: border-box;
  font-weight: bold;
  cursor: pointer;
}
.top :first-child {
  border: 0;
}
.top .hac {
  background: #1875f0;
  color: #fff;
}
.head {
  display: flex;
  /* width: 1520px; */
}
.head > div {
  flex: 1;
  border-left: 1px solid #fff;
  box-sizing: border-box;
  height: 140px;
  background: #f6f6f6;
}
.head :first-child {
  border-left: 0px solid #fff;
}
.name {
  font-size: 18px;
  color: #000000;
  height: 24px;
  text-align: center;
  margin-top: 23px;
  margin-bottom: 27px;
  font-weight: bold;
}
.count {
  height: 50px;
  font-size: 36px;
  color: #085dab;
  text-align: center;
  line-height: 50px;
}
.tabs {
  margin-top: 38px;
  border: 1px solid #dddddd;
  width: 398px;
  height: 67px;
  display: flex;
  font-size: 20px;
}
.tabs > div {
  flex: 1;
  font-size: 20px;
  height: 67px;
  line-height: 67px;
  text-align: center;
  font-weight: bold;
}
.tabs:first-child {
  border-right: 1px solid #ddd;
}
.tabs .tabac {
  background: #e0eefe;
}
.thead {
  background: #e0eefe;
  border: 1px solid #dddddd;
  /* width: 1490px; */
  height: 67px;
  line-height: 67px;
}
.thead > div {
  float: left;
  height: 67px;
  border-right: 1px solid #ddd;
  box-sizing: border-box;
  text-align: center;
  font-weight: bold;
  font-size: 20px;
}
.tbody {
  /* width: 1492px; */
  /* display: inline-block; */
  overflow: hidden;
  height: 60px;
  line-height: 60px;
  border: 1px solid #ddd;
  box-sizing: border-box;
  margin-top: -2px;
}
.tbody > div {
  height: 60px;
  /* line-height: 160px; */
  float: left;
  border-right: 1px solid #ddd;
  box-sizing: border-box;
  text-align: center;
  font-size: 18px;
  color: #4a4a4a;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tbody > div > span {
  /* height: 30px;
  line-height: 30px; */
  /* padding: 0 20px; */
  white-space:normal; word-break:break-all;
  line-height: 20px;
}
.tbody > div > div {
  height: 30px;
  line-height: 30px;
  text-align: center;
  width: 240px;
}
.username {
  /* width: 200px; */
  width:30%;
}
.parsr {
  /* width: 256px; */
  width: 12%;
}
.accmoney {
  /* width: 278px; */
  width: 12%;
}
.txmoney {
  /* width: 260px; */
  width: 12%;

}
.tbody .accmoney {
    color: #fe0000;
}
.ptmoney {
  /* width: 270px; */
  width: 12%;
}
.ctrl {
  /* width: 220px; */
  width: 22%;
}
.tbody .ctrl {
  cursor: pointer;
}
</style>


